package com.wangxinyuchuan.algorithm.phase1;

/**
 * @author wangxinyuchuan
 * @version _2_求n的阶乘.java v1.0 2023/5/25 9:17 PM wangxinyuchuan Exp $
 */
public class _2_求n的阶乘 {
    public static void main(String[] args) {
        System.out.println(fun(3));
        System.out.println(fun(10));
        System.out.println(fun(2));
        System.out.println(fun(1));
    }

    public static int fun(int n) {
        int ans = 0;
        int curr = 1;

        for (int i = 1; i <= n; i++) {
            curr = curr * i;
            ans += curr;
        }

        return ans;
    }
}
